#import "BigTableHeaderCell.h"

//taken directly from chartConstructor by Tobias Hsughton with permission
//
/*
 *  BigTableHeaderCell.m
 *  MESLib
 * 
 * Copyright 2003-2009 Starline Software.
 * 
 * This file is part of MESLib.
 * 
 * MESLib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MESLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with MESLib. If not, see <http://www.gnu.org/licenses/>.
 */



@implementation BigTableHeaderCell

- (id)init
{
   if (self = [super init]) {
      grayImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headerCellGray" ofType:@"tif"]];
      blueImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headerCellBlue" ofType:@"tif"]];

      [self setEditable:NO];
      [self setWraps:NO];
   }
   return self;
}

- copyWithZone:(NSZone *)zone {
   BigTableHeaderCell *cell = (BigTableHeaderCell *)[super copyWithZone:zone];
   cell->grayImage = [grayImage retain];
   cell->blueImage = [blueImage retain];

   return cell;
}

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
   NSRect imageFrame;

   [grayImage setSize:NSMakeSize(NSWidth(cellFrame), NSHeight(cellFrame))];

   imageFrame.origin.x = 0;
   imageFrame.origin.y = 0;
   imageFrame.size = [grayImage size];

   [grayImage drawInRect:cellFrame fromRect:imageFrame operation:NSCompositeCopy fraction:1];

   cellFrame.size.height = 15; //this is so the text will be vertically centered
   cellFrame.origin.y += 6;

   [super drawWithFrame:cellFrame inView:controlView];
}

- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
   NSRect imageFrame;

   [blueImage setSize:NSMakeSize(NSWidth(cellFrame), NSHeight(cellFrame))];

   imageFrame.origin.x = 0;
   imageFrame.origin.y = 0;
   imageFrame.size = [blueImage size];

   [blueImage drawInRect:cellFrame fromRect:imageFrame operation:NSCompositeCopy fraction:1];

   cellFrame.size.height = 15; //this is so the text will be vertically centered
   cellFrame.origin.y += 6;

   [super drawWithFrame:cellFrame inView:controlView];
}

- (void)dealloc
{
   [grayImage release];
   [blueImage release];
   [super dealloc];
}


@end